﻿var array = null;
(function () {
    var src = $("#checkjs").attr("src");
    var op = src.substring(src.indexOf('?') + 1, src.indexOf('&'));
    urlArray(
            'http://user.go007.com/login.aspx?path={}',
            'http://user.go007.com/Register.aspx'
            ,'http://user.go007.com/InfosCenter/DisplayInfos.aspx'
        , 'http://user.go007.com/loginout.aspx?path={}'
        , 'http://' + window.location.hostname+'/ditu/tuiguan.aspx');
    $.ajax({
        url: "http://" + location.hostname + "/ajaxhandler.ashx",
        data: "action=CheckLogin&t=" + new Date().getMilliseconds() * 15243,
        success: function (d) {
            if (d != "" && d != null) {
                var u = cutstring(d.split('|')[1],18,'...');
                switch (op) {
                    case "1":
                        showHtml("loginStatus", "<span class=headLog><span>" + u + "  </span> <a href=" + array[2] + ">进入管理中心</a>", " ", "<a href=" + GetHref(array[3]) + " class=exit>退出</a>" + "&nbsp;|&nbsp;<a href='" + array[4] +"'>我要推广</a>" + "<span style='color:#dfdfdf;'>|</span></span>");
                        break;
                    case "2":
                        showHtml("loginStatus", "<a href=" + array[2] + ">" + u + " 您好！", "", "&nbsp;|&nbsp;<a href='" + array[4] +"'>我要推广</a>");
                        break;
                    case "3":
                        showHtml("loginStatus", "[" + u + " 您好！ &nbsp;<a href=" + array[2] + ">进入管理中心</a>", "|", "&nbsp;<a  href=" + GetHref(array[3]) + ">退出</a>&nbsp;|&nbsp;<a href='" + array[4] + "'>我要推广</a>]");
                        break;
                    case "4":
                        showHtml("loginStatus", "<span class=headLog><span>" + u + " 欢迎您 </span><a href=" + array[2] + ">进入管理中心</a>", "|", "<a href=" + GetHref(array[3]) + " class=exit>退出</a>&nbsp;|&nbsp;<a href='" + array[4] + "'>我要推广</a></span>");
                        break;
					case "5":
                        showHtml("loginStatus", "<strong>" + u + "</strong>&nbsp;欢迎您!&nbsp;&nbsp;<a  style=\"color: #FF0000;font-weight: bold;\" href='" + array[2] + "'>进入管理中心&nbsp;</a>", "", "<a href=" + GetHref(array[3]) + "  style=\"color: #FF0000;font-weight: bold;\">退出</a>&nbsp;|&nbsp;<a href='" + array[4] + "'>我要推广</a>");
                        break;
                    case "6":
                        $("#divhea2").after('<span class="Six">您好! ' + u + ' <a href="' + array[2] + '">进入管理中心</a><a href="' + GetHref(array[3]) + '" >退出</a>&nbsp;|&nbsp;<a href=\'' + array[4] + '\'>我要推广</a></span>');
                        $(".Five").attr("class", "Seven");
                        break;
                    case "7":
                        $("#divhea2 > li:last-child").before('<li class="Sign">您好! ' + u + ' <a href="' + array[2] + '">进入管理中心</a><a href="' + GetHref(array[3]) + '" >退出</a>&nbsp;|&nbsp;<a href=\'' + array[4] + '\'>我要推广</a></li>');
                        $("#divhea2 > li:last-child").attr("class", "riAdd1");
                        break;
                    default:
                        alert(op);
                        break;
                }
            } else {
                switch (op) {
                    case "1":
                        showHtml("loginStatus", "<a href=" + GetHref(array[0]) + " class=\"bg3\">登录</a>", " ", "<a href=" + array[1] + ">注册</a>&nbsp;&nbsp;|&nbsp;<a href='" + array[4] + "'>我要推广</a>");
                        break;
					case "2":
                        showHtml("loginStatus", "<a href='" + GetHref(array[0]) + "'>登录</a>", "|", "<a  href=" + array[1] + ">注册</a>&nbsp;|&nbsp;<a href='" + array[4] + "'>我要推广</a>");
                        break;
                    case "3":
                        showHtml("loginStatus", "<a href='" + GetHref(array[0]) + "'>登录</a>", "|", "&nbsp;<a  href=" + array[1] + ">注册</a>&nbsp;|&nbsp;<a href='" + array[4] + "'>我要推广</a>");
                        break;
                    case "4":
                        var imageHost = $("#hdImageHost").val();
						var cityIndex = $("#hdCityIndex").val();
                        showHtml("loginStatus", "<div class=headReg><a href=" + array[1] + ">注册</a></div><div class=headLog><a href=" + cityIndex + " class=back_home>首页</a>", "", "<a href=" + GetHref(array[0]) + "><img src='" + imageHost + "03/list_06_02.gif'  width=69 height=17></a>&nbsp;|&nbsp;<a href='" + array[4] + "'>我要推广</a></div>");
                        break;
					case "5":
                        showHtml("loginStatus", "<a href='" + GetHref(array[0]) + "'>登录</a>", "|", "&nbsp;<a  href=" + array[1] + ">注册</a>&nbsp;|&nbsp;<a href='" + array[4] + "'>我要推广</a>");
                        break;
                    case "6":
                        $("#divhea2").after('<span class=Thre><a href="' + GetHref(array[0]) + '">登录</a></span><span class=Four><a href="' + array[1] + '">注册</a></span><span class=Four><a href=\'' + array[4] + '\'>我要推广</a></span>');
                        break;
                    case "7":
                        $("#divhea2 > li:last-child").before('<li class=User id="divhea2"><a href="' + GetHref(array[0]) + '" >登录</a></li><li class=User1><a href="' + array[1] + '">注册</a></li><li class=User1><a href=\'' + array[4] + '\'>我要推广</a></li>');
                        break;
                    default:
                        alert('检测用户出错请通知管理员，类型：{'+op+'}');
                        break;
                }
            }
        }
    });
})();
//将获得的地址转换成数组
function urlArray(login, register, my, loginout, tuiguan) {
    array = {
        0: login,
        1: register,
        2: my,
        3: loginout,
        4: tuiguan
    };
    return array;
}
//以下函数用于节约资源，避免代码重复
function showHtml(a,b,c,d){
    var html = document.getElementById(a);
    var result = b + c + d;
    html.innerHTML = result;
}
function GetHref(url)
{
    var uri = window.location.href.replace(":" + window.location.port,"");
    return url.replace("{}",uri).toString();
}